<template>
  <div class="rights">
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-table
      class="mt-15 mb-15"
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        type="index"
        width="50">
      </el-table-column>
      <!-- prop表示每一列渲染的数据的字段名 -->
      <el-table-column
        prop="authName"
        label="权限名称">
      </el-table-column>
      <el-table-column
        prop="path"
        label="路径">
      </el-table-column>
      <el-table-column
        label="层级">
        <!-- 此处写法改成作用域插槽，目的是为了能够使用过滤器 -->
        <template slot-scope="scope">
          <!-- <span>{{scope.row.level | fmtLevel}}</span> -->
          <el-tag type="primary" v-if="scope.row.level === '0'">一级</el-tag>
          <el-tag type="success" v-if="scope.row.level === '1'">二级</el-tag>
          <el-tag type="danger" v-if="scope.row.level === '2'">三级</el-tag>
        </template>
    </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { getRightList } from '@/api'
export default {
  data () {
    return {
      tableData: []
    }
  },
  // 创建局部过滤器
  filters: {
    fmtLevel: function (level) {
      switch (level) {
        case '0':
          return '一级'
        case '1':
          return '二级'
        default:
          return '三级'
      }
    }
  },
  created () {
    this.initTable()
  },
  methods: {
    // 初始化表格数据方法
    initTable () {
      // 此处传递参数'list'为后台规定，获取的是表格数据
      getRightList('list')
        .then(res => {
          this.tableData = res.data.data
        })
    }
  }
}
</script>
